import {
  getLineCodeList,
  getProdOrderStatusList
} from '@/api/print/mesProdOrder';
import { getDict } from '@/api/common';

// 列表头按钮配置
export const operateList = [
  {
    name: $i18n.t('mesOtherCodePrinting.print'),
    type: 'primary',
    icon: 'el-icon-printer',
    handleName: 'printBarCode', // 点击时返回的标识
    isSingle: true, // 至少选择一条
    // 是否可点击；
    disabled: (data) => {
      return data.length !== 1
    }
  },
  {
    name: $i18n.t('mesOtherCodePrinting.clear'),
    type: 'primary',
    icon: 'el-icon-printer',
    handleName: 'clearBarcode', // 点击时返回的标识
    // 只能选择一条
    isSingle: true,
    // 是否可点击；
    disabled: (data) => {
      return data.length !== 1
    }
  },
  {
    name: $i18n.t('mesOtherCodePrinting.reprint'),
    type: 'primary',
    icon: 'el-icon-brush',
    handleName: 'repairPrint', // 点击时返回的标识
    isSingle: true, // 至少选择一条
    // auth: 'mes:otherCode:reprint',
    // 是否可点击；
    disabled: (data) => {
      return data.length !== 1
    }
  }
]

// 行末按钮配置
export const rowConfig = []

// 搜索条件配置
export const searchConfig = {
  data () {
    const self = this
    return {
      searchDialog: {
        inline: true,
        formDesc: {
          orderCode: {
            type: 'input',
            label: $i18n.t('mesOtherCodePrinting.orderCode')
          },
          prodCode: {
            type: 'input',
            label: $i18n.t('mesOtherCodePrinting.prodCode')
          },
          orderStatus: {
            label: $i18n.t('mesOtherCodePrinting.orderStatus'),
            type: 'select',
            prop: {
              value: 'value',
              text: 'description'
            },
            options: async (data) => {
              const list = await getProdOrderStatusList()
              return list.data.result
            }
          },
          planBeginDate: {
            type: 'daterange',
            label: $i18n.t('mesOtherCodePrinting.planBeginDate'),
            attrs: {
              valueFormat: 'yyyy-MM-dd',
              searchArrKey: ['planBeginDateMin', 'planBeginDateMax']
            }
          },
          lineCode: {
            label: $i18n.t('common.line'),
            type: 'select',
            prop: {
              value: 'modelingCode',
              text: 'modelingName'
            },
            options: async (data) => {
              const params = {
                modelingCode: self.$store.getters.factoryCode,
                level: 5
              }
              const list = await getLineCodeList(params)
              return list.data.result
            }
          }
        }
      },
    }
  }
}

// 补打列表搜索配置
export const repairSearchConfig = {
  data () {
    const self = this
    return {
      repairSearchConfig: {
        inline: true,
        formDesc: {
          codeType: {
            label: $i18n.t("mesOtherCodePrinting.codeType"),
            type: 'select',
            layout: 12,
            prop: {
              value: 'value',
              text: 'description'
            },
            options: async (data) => {
              const list = await getDict('mes_code_type');
              return list.data.result
            }
          },
          status: {
            label: $i18n.t('common.status'),
            type: 'select',
            layout: 12,
            prop: {
              value: 'value',
              text: 'description'
            },
            options: async (data) => {
              const list = await getDict('mes_barcode_reprint_status')
              return list.data.result
            }
          },
        }
      }
    }
  }
}

// 补打列表上方按钮
export const operateRepairList = [
  {
    name: $i18n.t("common.add"),
    type: "primary",
    icon: "el-icon-circle-plus-outline",
    handleName: "add",
  },
]

// 补打列表操作按钮
export const repairRowConfig = [
  {
    name: $i18n.t("common.delete"),
    type: "danger",
    class: "row-btn-primary",
    handleName: "delete",
    show: (row) => {
      return row.status === 'noExamine';
    }
  },
  {
    name: $i18n.t("common.print"),
    type: "primary",
    class: "row-btn-primary",
    handleName: "print",
    show: (row) => {
      return row.status === 'examinePass' && row.isPrint === '0';
    }
  },
];

